/*
 * DemoImageAndAnimationState.h
 *
 *  Created on: 2011-11-11
 *      Author: baixp
 */

#ifndef DEMOIMAGEANDANIMATIONSTATE_H_
#define DEMOIMAGEANDANIMATIONSTATE_H_
#include "Lib9.h"
using namespace lib9bada;
class DemoImageAndAnimationState: public Lib9, public L9IState {
private:
	L9Sprite* pSpriteImage;
	L9Animation* pAnim;
	bool bPlayAnimation;
public:
	DemoImageAndAnimationState(Application* pApp);
	virtual ~DemoImageAndAnimationState();

	/*static*/ int xx;
	void test1(int i){
		xx=i;
		int xy=xx+2;
	}
	void Init() {
		// TODO Auto-generated method stub
	}

	void Update() {
		// TODO Auto-generated method stub
		//按5键或者D键盘的中间键将状态(没有按键的则点击屏幕任意一点)播放或者停止动画
		if (isKeyPressed(K_KEY_5 | K_KEY_OK)||getPointerX() > 0) {
			bPlayAnimation = !bPlayAnimation;
		}
	}

	void Paint() {
		// TODO Auto-generated method stub
		// 清屏
		fillScreen(0xFFFFFFFF);

		int y = 0;
		if (bPlayAnimation) {
			pAnim->updateAnimation(pFG);

			y = pAnim->getAnimY() + pAnim->getAnimHeight();
			pFG->SetForegroundColor(Color(0xFF000000));
			pL9Str->drawLine(pFG,"按5键停止", 0, y, SCR_W,pL9Str->K_Line_Align_Center);
		} else {
			// 这里居中显示图片
			int w = pSpriteImage->getFrameWidth(0);
			int h = pSpriteImage->getFrameHeight(0);
			pSpriteImage->paintFrame(pFG, 0, (SCR_W - w) >> 1, (SCR_H - h)>> 1);
			y = h + ((SCR_H - h) >> 1);
			pFG->SetForegroundColor(Color(0xFF000000));
			pL9Str->drawLine(pFG, "按5键播放", 0, y, SCR_W,pL9Str->K_Line_Align_Center);
		}
	}
};

#endif /* DEMOIMAGEANDANIMATIONSTATE_H_ */
